import abc


# 密码生成器，以迭代器方式返回密码
class PasswordGenerator:
    def __iter__(self):
        return self

    @abc.abstractmethod
    def __next__(self):
        pass


# 从文件中读取密码，并以迭代器方式返回，文件中每个密码单独一行，见password.txt
class BasePasswordGenerator(PasswordGenerator):
    def __init__(self, password_file_path):
        self.current_index = -1
        self.password_file_path = password_file_path
        self.cracking_passwords = []
        self.__load_password()

    def __load_password(self):
        with open(self.password_file_path, 'r', encoding='utf-8') as fr:
            self.cracking_passwords = [password.strip() for password in fr.readlines()]

    def __next__(self):
        self.current_index += 1
        if self.current_index >= len(self.cracking_passwords):
            raise StopIteration()

        return self.cracking_passwords[self.current_index]
